package com.pgybook.front.action;

import com.pgybook.db.entity.domain.CustomerDeliverAddress;
import com.pgybook.front.action.vo.MemberAddressVO;
import com.pgybook.front.service.MemberAddressService;
import com.pgybook.front.web.util.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.WebRequest;

import java.util.List;

import static com.pgybook.front.web.util.FrontUtil.CUSTOMER_ID_KEY;
import static com.pgybook.front.web.util.FrontUtil.redirectAction;

/**
 * Created with IntelliJ IDEA.
 * User: feeling
 * Date: 13-11-21
 * Time: 下午6:30
 */
@Controller
@RequestMapping("member/address")
public class MemberAddressAct {


    /**
     * 添加地址
     *
     * @return
     */

    public String addAddress(MemberAddressVO addressVO, BindingResult br, ModelMap mmap, WebRequest wq) {

        return "";

    }


    public String removeAddress(MemberAddressVO addressVO, BindingResult br, ModelMap mmap, WebRequest wq) {
        return "";
    }

    public String modifyAddress(MemberAddressVO addressVO, BindingResult br, ModelMap mmap, WebRequest wq) {

        return "";
    }

    @RequestMapping("index.jspx")
    public String listAdderss(ModelMap mmap, @Session(CUSTOMER_ID_KEY) Long custId, WebRequest wq) {
        List<CustomerDeliverAddress> addresses = memberAddressSrv.list(custId);
        mmap.put("address", addresses);

        return "/client_address";
    }

    @RequestMapping("setdefault.jspx")
    public String setDefaultAddress(@RequestParam Integer addressId, ModelMap mmap, @Session(CUSTOMER_ID_KEY) Long custId, WebRequest wq) {
        boolean success = memberAddressSrv.setAddressDefault(custId, addressId);
        mmap.put("set", success);
        return redirectAction("/member/address/index");
    }


    @Autowired
    MemberAddressService memberAddressSrv;
}
